package org.coopac.dao.impl;

import java.util.HashMap;
import java.util.List;

import org.coopac.dao.IPersonaDAO;
import org.coopac.model.CoopacDocumentoPersona;
import org.coopac.model.CoopacPersona;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository("PersonaDAO")
public class PersonaDAO extends BaseDaoImpl<CoopacPersona> implements IPersonaDAO {
	
	@Autowired
	SessionFactory sessionFactory;
	
	@Override
	protected SessionFactory getSessionFactory() {
		return sessionFactory;
	}

	@Override
	public List<CoopacPersona> listar() {
		return super.listar(CoopacPersona.class);
	}

	@Override
	public void save(CoopacPersona persona) {
		super.save(persona);
	}

	@Override
	public void update(CoopacPersona persona) {
		super.update(persona);
	}

	@Override
	public void delete(CoopacPersona persona) {
		super.delete(persona);
	}

	@Override
	public CoopacPersona getById(int id) {
		return (CoopacPersona) super.getById(CoopacPersona.class, id);
	}

	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Override
	public List<String> listarPersonaDocumento() {		
		String consulta = 
		"SELECT CONCAT(persona.apellidoPaternoRazonSocial,' ',persona.apellidoMaterno,' '," +
		"persona.nombrePersonaNombreComercial,' - ',documento.numero) as nombreBusqueda FROM CoopacPersona as persona, " +
		"CoopacDocumentoPersona as documento where persona.idPersona = documento.coopacPersona.idPersona";
		
		List list = getSessionFactory().getCurrentSession()
		.createQuery(consulta).list(); 
		
		return list;
	}
	
}
